package com.subway.babynote.syncdata;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;


import org.json.*;



public class ClientDataRecord {
	public static class ts extends ClientDataRecordBase
	{
		public int client_id = -1;
		public int ts = 0;
		public ts()
		{
			this.init_type();
		}

		public ts (JSONObject jsono)
		{
			this.init_type();
			this.client_id = ClientDataRecordBase.read_int(jsono, PostParam.ts.client_id);
			this.ts = ClientDataRecordBase.read_int(jsono, PostParam.ts.ts);	
		}
		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.ts.client_id, this.client_id);
				jsono.put(PostParam.ts.ts, this.ts);
				return jsono;
			}
			catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}

		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.ts;
		}
		
	}
	public static class map_ClientDataRecord extends ClientDataRecordBase
	{
		public Map<String, ClientDataRecordBase> map = new TreeMap<String, ClientDataRecordBase>();

		public map_ClientDataRecord()
		{
			this.init_type();
		}
		
		public map_ClientDataRecord(JSONObject jsono)
		{
			this.init_type();
			Iterator<String> it = jsono.keys();
			while(it.hasNext())
			{
				String str = it.next();
				JSONObject j = ClientDataRecordBase.read_json(jsono, str);
				if(j != null)
				{
					ClientDataRecordBase crb = ClientDataRecordBase.fromJSON(j);
					map.put(str,crb);
				}
			}
		}
		@Override
		protected JSONObject to_JSON() {
			JSONObject jsono = new JSONObject();
			Set<String> keys = map.keySet();
			Iterator<String> it = keys.iterator();
			
			while(it.hasNext())
			{
				String str = it.next();
				ClientDataRecordBase crb = map.get(str);
				ClientDataRecordBase.write_jsono(jsono, str, crb.toJSON());
			}
			return jsono;
		}

		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.map;
		}
		
	}
	public static class list_ClientDataRecord extends ClientDataRecordBase
	{
		public List<ClientDataRecordBase> list = new ArrayList<ClientDataRecordBase>();
		static final String arraytype = "a";
		public list_ClientDataRecord()
		{
			this.init_type();
		}
		public list_ClientDataRecord(JSONObject jsono)
		{
			this.init_type();
			JSONArray jsona = ClientDataRecordBase.read_jsonA(jsono, arraytype);
			if(jsona != null)
				list = ClientDataRecordBase.fromJSONArray(jsona);
		}
		@Override
		protected JSONObject to_JSON() {
			JSONObject jsono = new JSONObject();
			JSONArray jsona = ClientDataRecordBase.toJSONArray(list);
			ClientDataRecordBase.write_jsona(jsono, arraytype, jsona);
			return jsono;
		}

		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.list;
		}
		
	}
	public static class returnValue extends ClientDataRecordBase{
		public int errcode = 0;
		public String errmsg = null;
		public returnValue(int ecode, String emsg)
		{
			this.init_type();
			errcode = ecode;
			errmsg = emsg;
		}
		public returnValue(JSONObject jsono)
		{
			this.init_type();
			try
			{
				this.errcode = ClientDataRecordBase.read_int(jsono, PostParam.ReturnValue_Param.return_status);
				this.errmsg = ClientDataRecordBase.read_str(jsono, PostParam.ReturnValue_Param.err_message);
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			 }
		}
		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				ClientDataRecordBase.write_str(jsono, PostParam.ReturnValue_Param.err_message, this.errmsg);
				jsono.put(PostParam.ReturnValue_Param.return_status, this.errcode);
				return jsono;
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.returnValue;
		}
	}
	public static class hwAvgRecord extends ClientDataRecordBase
	{	
		public int age = 0;
		public boolean gender = true;
		public float min = 0;
		public float mid = 0;
		public float max = 0;
		public int ts = 0;
		
		public hwAvgRecord()
		{
			this.init_type();
		}
		public hwAvgRecord(JSONObject jsono)
		{
			this.init_type();
			try
			{
				this.age = ClientDataRecordBase.read_int(jsono, PostParam.hwAvgRecord.age);
				this.gender = jsono.getBoolean(PostParam.hwAvgRecord.gender);
				this.min = ClientDataRecordBase.read_float(jsono, PostParam.hwAvgRecord.min);
				this.mid = ClientDataRecordBase.read_float(jsono, PostParam.hwAvgRecord.mid);
				this.max = ClientDataRecordBase.read_float(jsono, PostParam.hwAvgRecord.max);
				this.ts = ClientDataRecordBase.read_int(jsono, PostParam.hwAvgRecord.ts);				
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			 }
		}
		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.hwAvgRecord.age, this.age);
				jsono.put(PostParam.hwAvgRecord.gender, this.gender);
				jsono.put(PostParam.hwAvgRecord.min, this.min);
				jsono.put(PostParam.hwAvgRecord.max, this.max);
				jsono.put(PostParam.hwAvgRecord.mid, this.mid);
				jsono.put(PostParam.hwAvgRecord.ts, this.ts);
				return jsono;
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.hwAvgRecord;
		}
	}
	
	public static class hwdefaultRecord extends ClientDataRecordBase
	{
		public int age = 0;
		public boolean gender = true;
		public uxRecord ux = new uxRecord();
		public hwdefaultRecord()
		{
			this.init_type();
		}
		
		public hwdefaultRecord(JSONObject jsono)
		{
			this.init_type();
			try
			{
				this.age = ClientDataRecordBase.read_int(jsono, PostParam.ux.age);
				this.gender = jsono.getBoolean(PostParam.ux.gender);
				JSONObject uxj = jsono.getJSONObject(PostParam.ux.ux);
				ux = new uxRecord(uxj);
					
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			 }
		}

		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.ux.age, this.age);
				jsono.put(PostParam.ux.gender, this.gender);
				jsono.put(PostParam.ux.ux, this.ux.toJSON());
				return jsono;
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}

		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.hwdefaultRecord;
		}
	}
	
	public static class food_uxRecord extends ClientDataRecordBase
	{
		public int food_id = 0;
		public uxRecord ux = new uxRecord();
		
		public food_uxRecord()
		{
			this.init_type();
		}
		public food_uxRecord(JSONObject jsono)
		{
			this.init_type();
			try
			{
				this.food_id = ClientDataRecordBase.read_int(jsono, PostParam.ux.ux);
				JSONObject uxj = jsono.getJSONObject(PostParam.ux.ux);
				ux = new uxRecord(uxj);
				
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			 }
		}

		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.ux.food_id, this.food_id);
				jsono.put(PostParam.ux.ux, this.ux.toJSON());
				return jsono;
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.food_uxRecord;
		}
	}
	
	public static class food_defaultRecord extends ClientDataRecordBase
	{
		public int age = 0;
		public boolean gender = true;
		public food_uxRecord fux = new food_uxRecord();
		
		public food_defaultRecord()
		{
			this.init_type();
			
		}
		public food_defaultRecord(JSONObject jsono)
		{
			this.init_type();
			try
			{
				this.age = ClientDataRecordBase.read_int(jsono, PostParam.ux.age);
				this.gender = jsono.getBoolean(PostParam.ux.gender);
				JSONObject uxj = jsono.getJSONObject(PostParam.ux.fux);
				fux = new food_uxRecord(uxj);
					
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			 }
		}
		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.ux.age, this.age);
				jsono.put(PostParam.ux.gender, this.gender);
				jsono.put(PostParam.ux.fux, this.fux.toJSON());
				return jsono;
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.food_defaultRecord;
		}
		
	}
	
	public static class uxRecord extends ClientDataRecordBase
	{
		public float min = 0;
		public float max = 0;
		public int ts = 0;
		public List<Float> l= new ArrayList<Float>();

		public uxRecord()
		{
			this.init_type();
			
		}
		public uxRecord(JSONObject jsono)
		{
			this.init_type();
			try
			{
				this.min = ClientDataRecordBase.read_float(jsono, PostParam.uxRecord.min);
				this.max = ClientDataRecordBase.read_float(jsono, PostParam.uxRecord.max);
				this.ts = ClientDataRecordBase.read_int(jsono, PostParam.uxRecord.ts);
				this.l = StringUtil.str2floats(ClientDataRecordBase.read_str(jsono, PostParam.uxRecord.l));		
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			 }
		}
		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				ClientDataRecordBase.write_str(jsono, PostParam.uxRecord.l, StringUtil.floats2str(l));
				jsono.put(PostParam.uxRecord.min, min);
				jsono.put(PostParam.uxRecord.max, max);
				jsono.put(PostParam.uxRecord.ts, ts);
				return jsono;
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.uxRecord;
		}
		
	}
	public static class weibocredential extends ClientDataRecordBase{
		public String token = null;
		public String tokenkey = null;
		public weibocredential(String t, String tk)
		{
			this.init_type();
			this.token = t;
			this.tokenkey = tk;			
		}
		public weibocredential(JSONObject jsono)
		{
			this.init_type();
			this.token = ClientDataRecordBase.read_str(jsono, PostParam.weibocredential.token);
			this.tokenkey = ClientDataRecordBase.read_str(jsono, PostParam.weibocredential.tokenkey);
		}
		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				ClientDataRecordBase.write_str(jsono, PostParam.weibocredential.token, this.token);
				ClientDataRecordBase.write_str(jsono, PostParam.weibocredential.tokenkey, this.tokenkey);
				return jsono;
			}
			 catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.weibocredential;
		}
	}
	public static class weiboRecord extends ClientDataRecordBase{

		public String username = null;
		public String credential = null;
		public int ts = -1;
		public weiboRecord(String user, String oa, int t)
		{
			this.init_type();
			this.username = user;
			this.credential = oa;
			this.ts = t;
		}
		public weiboRecord(JSONObject jsono)
		{
			this.init_type();
			this.username = ClientDataRecordBase.read_str(jsono, PostParam.weiboRecord.username);
			this.credential = ClientDataRecordBase.read_str(jsono, PostParam.weiboRecord.credential);
			this.ts = ClientDataRecordBase.read_int(jsono, PostParam.weiboRecord.ts);
		}
		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				ClientDataRecordBase.write_str(jsono, PostParam.weiboRecord.username, this.username);
				ClientDataRecordBase.write_str(jsono, PostParam.weiboRecord.credential, this.credential);
				jsono.put(PostParam.weiboRecord.ts, this.ts);
				return jsono;
			}
			 catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.weiboRecord;
		}
		
	}
	public static class hwUserRecord extends ClientDataRecordBase{
		//public int user_id = -1;
		public int client_id = -1;
		public float value = 0;
		public int ts = -1;
		public hwUserRecord(int c_id,float v, int t)
		{
			this.init_type();
			//this.user_id = id;
			this.client_id = c_id;
			this.value = v;
			this.ts = t;
		}
		public hwUserRecord(JSONObject jsono)
		{
			this.init_type();
			this.client_id = ClientDataRecordBase.read_int(jsono, PostParam.hwUserRecord.client_id);
			this.value = ClientDataRecordBase.read_float(jsono, PostParam.hwUserRecord.value);
			this.ts = ClientDataRecordBase.read_int(jsono, PostParam.hwUserRecord.ts);
		}
		@Override
		protected JSONObject to_JSON() {
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.hwUserRecord.client_id, this.client_id);
				jsono.put(PostParam.hwUserRecord.value, this.value);
				jsono.put(PostParam.hwUserRecord.ts, this.ts);
				return jsono;
			}
			 catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			 }
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.hwUserRecord;
		}
	}
	public static class contactRecord extends ClientDataRecordBase{
		public String name = "";
		public String value="";
		public int ts = -1;
		public contactRecord(String n, String v, int t)
		{
			this.init_type();
			this.name = n;
			this.value = v;
			this.ts = t;
		}
		public contactRecord(JSONObject jsono)
		{
			 this.init_type();
			 this.name = ClientDataRecordBase.read_str(jsono, PostParam.contactRecord.name);
			 this.value = ClientDataRecordBase.read_str(jsono, PostParam.contactRecord.value);
			 this.ts = ClientDataRecordBase.read_int(jsono, PostParam.contactRecord.ts);
		}

		@Override
		protected JSONObject to_JSON() {
			JSONObject jsono = new JSONObject();
			ClientDataRecordBase.write_str(jsono, PostParam.contactRecord.name, this.name);
			ClientDataRecordBase.write_str(jsono, PostParam.contactRecord.value, value);
			try {
				jsono.put(PostParam.contactRecord.ts, ts);
			
			// TODO Auto-generated method stub
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.contactRecord;
		}
		
	}
	public static class loadinfoRecord extends ClientDataRecordBase
	{
		public String content = "";
		public int ts = -1;
		public loadinfoRecord(String s, int t)
		{
			this.init_type();
			this.content = s;
			this.ts = t;
		}
		public loadinfoRecord(JSONObject jsono)
		{
			this.init_type();
			this.content = ClientDataRecordBase.read_str(jsono, PostParam.loadinfoRecord.content);
			this.ts = ClientDataRecordBase.read_int(jsono, PostParam.loadinfoRecord.ts);
		}
		@Override
		protected JSONObject to_JSON() {
			JSONObject jsono = new JSONObject();
			ClientDataRecordBase.write_str(jsono, PostParam.loadinfoRecord.content, this.content);
			
			try {
				jsono.put(PostParam.loadinfoRecord.ts, ts);
			
			// TODO Auto-generated method stub
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.loadinfoRecord;
		}
		
	}
	
	public static class usersRecord extends ClientDataRecordBase {
		//_id, user_id,first_use_time,birth,gender,email,passwd,first_reg_time,isuser,ts 
		   public int user_id= -1;
		   	   
		   public int birth = -1;
		   public int first_use_time = -1; //f
		   public boolean gender=true;
		   public String email = "";
		   public String passwd = "";		   
		   public int first_reg_time = -1;
		   public boolean isuser = false;
		   public int ts = -1;
		   public usersRecord()
		   {
			   this.init_type();
			   this.user_id = -1;
			   this.birth = -1;
			   this.gender = true;
			   this.email = "";
			   this.passwd = "";
			   this.first_reg_time = -1;
			   this.first_use_time = -1;
			   this.ts = -1;
		   }
		   public usersRecord(JSONObject jsono)
		   {
			   this.init_type();
			   try
			   {
				   this.user_id = ClientDataRecordBase.read_int(jsono, PostParam.usersRecord_Param.user_id);
				   this.birth = ClientDataRecordBase.read_int(jsono, PostParam.usersRecord_Param.birth);
				   
				   this.gender = jsono.getBoolean(PostParam.usersRecord_Param.gender);
				   this.email = ClientDataRecordBase.read_str(jsono, PostParam.usersRecord_Param.email);
				   this.passwd = ClientDataRecordBase.read_str(jsono, PostParam.usersRecord_Param.passwd);
				   
				   this.first_reg_time = ClientDataRecordBase.read_int(jsono, PostParam.usersRecord_Param.first_reg_time);
				   this.first_use_time = ClientDataRecordBase.read_int(jsono, PostParam.usersRecord_Param.first_use_time);
				   
				   ts = ClientDataRecordBase.read_int(jsono, PostParam.usersRecord_Param.ts);
			   }
			   catch(JSONException je)
			   {
				   je.printStackTrace();
			   }
		   }		   
		   
		   protected JSONObject to_JSON()
		   {
				try
				{
					JSONObject jsono = new JSONObject();
					jsono.put(PostParam.usersRecord_Param.user_id, this.user_id);					
					jsono.put(PostParam.usersRecord_Param.birth, this.birth);
					
					jsono.put(PostParam.usersRecord_Param.first_reg_time, this.first_reg_time);
					jsono.put(PostParam.usersRecord_Param.first_use_time, this.first_use_time);
					jsono.put(PostParam.usersRecord_Param.gender, this.gender);
					ClientDataRecordBase.write_str(jsono, PostParam.usersRecord_Param.email, this.email);
					ClientDataRecordBase.write_str(jsono, PostParam.usersRecord_Param.passwd, this.passwd);
					jsono.put(PostParam.usersRecord_Param.ts,this.ts);
					return jsono;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					System.out.println("JSON error for food_propRecord:" + e.getMessage());
					e.printStackTrace();
					return null;
				}	
			}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.usersRecord;
		}
	}
	
	
	public static class user_auth_info extends ClientDataRecordBase
	{
		public int id = -1;
		public String imsi = "";
		public String imei = "";
		public int client_id = -1;
		public boolean isuser = false;
		public int ts = -1;
		public user_auth_info()
		{
			
		}
		public user_auth_info(JSONObject jsono)
		{
			this.init_type();
			id = ClientDataRecordBase.read_int(jsono,PostParam.user_auth_info_Param.id);
			imsi = ClientDataRecordBase.read_str(jsono, PostParam.user_auth_info_Param.imsi);
			imei = ClientDataRecordBase.read_str(jsono, PostParam.user_auth_info_Param.imei);
			ts = ClientDataRecordBase.read_int(jsono,PostParam.user_auth_info_Param.ts);
			client_id = ClientDataRecordBase.read_int(jsono,PostParam.user_auth_info_Param.client_id);
			String i = ClientDataRecordBase.read_str(jsono, PostParam.user_auth_info_Param.isuser);
			isuser = StringUtil.str2bool(i);
		}
		public user_auth_info(int uid, String ims, String ime, int clientid, int t)
		{			
			this.init_type();
			this.id = uid;
			this.imsi = ims;
			this.imei = ime;
			this.ts = t;
			this.client_id = clientid;
			this.isuser = false;
		}
		public user_auth_info(int uid, String ims, String ime,int clientid)
		{			
			this.init_type();
			this.id = uid;
			this.imsi = ims;
			this.imei = ime;
			this.client_id = clientid;
			this.ts = -1;
			this.isuser = false;
		}
		protected JSONObject to_JSON()
		{
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.user_auth_info_Param.id, id);
				ClientDataRecordBase.write_str(jsono, PostParam.user_auth_info_Param.imsi, imsi);
				ClientDataRecordBase.write_str(jsono, PostParam.user_auth_info_Param.imei, imei);
				jsono.put(PostParam.user_auth_info_Param.client_id, client_id);
				jsono.put(PostParam.user_auth_info_Param.ts, ts);
				ClientDataRecordBase.write_str(jsono,PostParam.user_auth_info_Param.isuser, StringUtil.bool2str(isuser));
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				System.out.println("JSON error for food_propRecord:" + e.getMessage());
				e.printStackTrace();
				return null;
			}	
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.user_auth_info;
		}
	}
	public static class food_propRecord extends ClientDataRecordBase
	{
		public int food_prop_id;
		public String food_prop;
		public int ts;
		public food_propRecord(JSONObject jsono)
		{
			this.init_type();
			food_prop_id = ClientDataRecordBase.read_int(jsono,PostParam.food_propRecord_Param.food_prop_id);
			this.food_prop = ClientDataRecordBase.read_str(jsono, PostParam.food_propRecord_Param.food_prop);
			this.ts = ClientDataRecordBase.read_int(jsono,PostParam.food_propRecord_Param.ts);
		
		}
		public food_propRecord(int id, String fp,int t)
		{
			this.init_type();
			this.food_prop_id = id;
			this.food_prop = fp;
			this.ts = t;
		}
		
		protected JSONObject to_JSON()
		{
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.food_propRecord_Param.food_prop_id, this.food_prop_id);
				ClientDataRecordBase.write_str(jsono, PostParam.food_propRecord_Param.food_prop, this.food_prop);
				jsono.put(PostParam.food_propRecord_Param.ts, this.ts);
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				System.out.println("JSON error for food_propRecord:" + e.getMessage());
				e.printStackTrace();
				return null;
			}	
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.food_propRecord;
		}
	}
	public static class feedRecord  extends ClientDataRecordBase
	{
		//_id,food_id,user_id,client_id,r_date,r_time,quantity,mark,ts
		public int food_id = -1;
		public int client_id = -1;
		public int r_time = -1;
		public int r_date = -1;
		public float quantity = 0;
		public int mark = 1;
		public int ts = 0;
		public feedRecord()
		{
			
		}
		public feedRecord(int fid, int cid,int time, int date, float q, int marks, int timestamp)
		{
			this.init_type();
			this.food_id = fid;
			this.client_id = cid;
			this.r_time = time;
			this.r_date = date;
			
			this.quantity = q;
			this.mark = marks;
			this.ts = timestamp;
		}
		public feedRecord(JSONObject jsono)
		{
			this.init_type();
			food_id = ClientDataRecordBase.read_int(jsono,PostParam.feedRecord_Param.food_id);
			client_id = ClientDataRecordBase.read_int(jsono,PostParam.feedRecord_Param.client_id);
			r_date = ClientDataRecordBase.read_int(jsono,PostParam.feedRecord_Param.r_date);
			r_time = ClientDataRecordBase.read_int(jsono,PostParam.feedRecord_Param.r_time);
			mark = ClientDataRecordBase.read_int(jsono,PostParam.feedRecord_Param.mark);
			quantity =ClientDataRecordBase.read_float(jsono,PostParam.feedRecord_Param.quantity);
			ts = ClientDataRecordBase.read_int(jsono,PostParam.feedRecord_Param.ts);				
		}
		
		protected JSONObject to_JSON()
		{
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.feedRecord_Param.food_id, food_id);
				jsono.put(PostParam.feedRecord_Param.client_id, client_id);
				jsono.put(PostParam.feedRecord_Param.r_date, r_date);
				jsono.put(PostParam.feedRecord_Param.r_time, r_time);
				
				jsono.put(PostParam.feedRecord_Param.mark, this.mark);
				
				jsono.put(PostParam.feedRecord_Param.quantity, quantity);
				jsono.put(PostParam.feedRecord_Param.ts, ts);
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				System.out.println("JSON error for feedRecord:" + e.getMessage());
				e.printStackTrace();
				return null;
			}	
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.feedRecord;
		}
	}
	
	public static class foodsRecord  extends ClientDataRecordBase
	{
		public int food_id ;
		public int food_prop_id;
		public String foodname;
		public String unit;
		public String category;
		public int ts;
		public foodsRecord(int id, int fnid, String fn, String ut, String cate, int timestamp)
		{
			this.init_type();
			this.food_id = id;
			this.food_prop_id = fnid;
			this.foodname = fn;
			this.unit = ut;
			this.category = cate;
			this.ts = timestamp;
		}
		
		public foodsRecord(JSONObject jsono) 
		{
		
			this.init_type();
			this.food_id = ClientDataRecordBase.read_int(jsono,PostParam.foodsRecord_Param.food_id);
			this.food_prop_id = ClientDataRecordBase.read_int(jsono,PostParam.foodsRecord_Param.food_prop_id);
			this.foodname = ClientDataRecordBase.read_str(jsono, PostParam.foodsRecord_Param.foodname);
			this.unit = ClientDataRecordBase.read_str(jsono, PostParam.foodsRecord_Param.unit);
			this.category = ClientDataRecordBase.read_str(jsono, PostParam.foodsRecord_Param.category);
			this.ts = ClientDataRecordBase.read_int(jsono,PostParam.foodsRecord_Param.ts);
		
		}
		protected JSONObject to_JSON()
		{
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.foodsRecord_Param.food_id, food_id);
				jsono.put(PostParam.foodsRecord_Param.food_prop_id, this.food_prop_id);
				ClientDataRecordBase.write_str(jsono, PostParam.foodsRecord_Param.foodname, this.foodname);
				ClientDataRecordBase.write_str(jsono, PostParam.foodsRecord_Param.unit, this.unit);
				ClientDataRecordBase.write_str(jsono, PostParam.foodsRecord_Param.category, this.category);
				jsono.put(PostParam.foodsRecord_Param.ts, ts);
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				System.out.println("JSON error for feedRecord:" + e.getMessage());
				e.printStackTrace();
				return null;
			}	
		}

		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.foodsRecord;
		}
		
	}
	public static class last_avgRecord  extends ClientDataRecordBase
	{
		public int food_prop_id;
		public int r_date;
		public String food_prop;
		public float yours;
		public float avgs;
		public float diffs;
		public int ts;
		
		public last_avgRecord(int fpid, int dt, String fp, float y, float a, float d, int t)
		{
			this.init_type();
			this.food_prop_id = fpid;
			this.food_prop = fp;			
			this.r_date = dt;
			this.yours = y;
			this.avgs = a;
			this.diffs = d;
			ts  = t;
		}
		public last_avgRecord(JSONObject jsono)
		{
			this.init_type();
			this.food_prop_id = ClientDataRecordBase.read_int(jsono,PostParam.last_avgRecord_Param.food_prop_id);
			this.r_date = ClientDataRecordBase.read_int(jsono, PostParam.last_avgRecord_Param.r_date);
			this.food_prop = ClientDataRecordBase.read_str(jsono, PostParam.last_avgRecord_Param.food_prop);
			this.yours = ClientDataRecordBase.read_float(jsono, PostParam.last_avgRecord_Param.yours);
			this.avgs = ClientDataRecordBase.read_float(jsono, PostParam.last_avgRecord_Param.avgs);
			this.diffs = ClientDataRecordBase.read_float(jsono, PostParam.last_avgRecord_Param.diffs);			
		
			this.ts = ClientDataRecordBase.read_int(jsono, PostParam.last_avgRecord_Param.ts);
		}
		protected JSONObject to_JSON()
		{
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.last_avgRecord_Param.food_prop_id, this.food_prop_id);
				ClientDataRecordBase.write_str(jsono, PostParam.last_avgRecord_Param.food_prop, this.food_prop);			
				jsono.put(PostParam.last_avgRecord_Param.r_date, this.r_date);
			
				jsono.put(PostParam.last_avgRecord_Param.yours, this.yours);
				jsono.put(PostParam.last_avgRecord_Param.avgs, this.avgs);
				jsono.put(PostParam.last_avgRecord_Param.diffs, this.diffs);
				jsono.put(PostParam.last_avgRecord_Param.ts, this.ts);
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				System.out.println("JSON error for feedRecord:" + e.getMessage());
				e.printStackTrace();
				return null;
			}	
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.last_avgRecord;
		}
		
	}
	public static class tipRecord  extends ClientDataRecordBase
	{
		public String content;
		public int ts;
		public int dayage;
		public tipRecord(String tip, int t, int da)
		{
			this.init_type();
			this.content = tip;
			this.ts = t;
			this.dayage = da;
		}
		
		public tipRecord(JSONObject jsono) 
		{
			this.init_type();
			this.content = ClientDataRecordBase.read_str(jsono, PostParam.tipRecord_Param.content);
			this.ts = ClientDataRecordBase.read_int(jsono,PostParam.tipRecord_Param.ts);
			this.dayage = ClientDataRecordBase.read_int(jsono,PostParam.tipRecord_Param.dayage);
		
		}
		protected JSONObject to_JSON()
		{
			try
			{
				JSONObject jsono = new JSONObject();
				ClientDataRecordBase.write_str(jsono, PostParam.tipRecord_Param.content, this.content);
				jsono.put(PostParam.tipRecord_Param.ts, this.ts);
				jsono.put(PostParam.tipRecord_Param.dayage, this.dayage);
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				System.out.println("JSON error for feedRecord:" + e.getMessage());
				e.printStackTrace();
				return null;
			}	
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.tipRecord;
		}
	}
	
	public static class feedbackRecord  extends ClientDataRecordBase
	{
		public int user_id;
		public int r_time;
		public String content;
		public int ts;
		public feedbackRecord(int uid, int dt, String c)
		{
			this.init_type();
			this.user_id = uid;
			this.r_time = dt;
			this.content = c;
			ts = 0;
		}
		public feedbackRecord(JSONObject jsono) 
		{
	
			this.init_type();
			this.user_id = ClientDataRecordBase.read_int(jsono,PostParam.feedbackRecord_Param.user_id);
			this.r_time = ClientDataRecordBase.read_int(jsono, PostParam.feedbackRecord_Param.r_time);
			this.content = ClientDataRecordBase.read_str(jsono, PostParam.feedbackRecord_Param.content);
			this.ts = ClientDataRecordBase.read_int(jsono, PostParam.feedbackRecord_Param.ts);
			
			
		}
		protected JSONObject to_JSON()
		{
			try
			{
				JSONObject jsono = new JSONObject();
				jsono.put(PostParam.feedbackRecord_Param.user_id, this.user_id);
				jsono.put(PostParam.feedbackRecord_Param.r_time, this.r_time);
				jsono.put(PostParam.feedbackRecord_Param.ts, this.ts);
				ClientDataRecordBase.write_str(jsono, PostParam.feedbackRecord_Param.content, this.content);						
				
				return jsono;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				System.out.println("JSON error for feedbackRecord:" + e.getMessage());
				e.printStackTrace();
				return null;
			}	
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.feedbackRecord;
		}
	}
	
	public static class tsType extends ClientDataRecordBase
	{	
		public map_ClientDataRecord c = new map_ClientDataRecord();
		private int init()
		{
			ts t = new ts();
			c.map.put(tableName.t_avg_height, t);
			t = new ts();
			c.map.put(tableName.t_avg_weight, t);
			t = new ts();
			c.map.put(tableName.t_feedbacks, t);
			t = new ts();
			c.map.put(tableName.t_food_default, t);
			t = new ts();
			c.map.put(tableName.t_food_prop, t);
			t = new ts();
			c.map.put(tableName.t_food_ux, t);
			t = new ts();
			c.map.put(tableName.t_foods, t);
			t = new ts();
			c.map.put(tableName.t_h_default, t);
			t = new ts();
			c.map.put(tableName.t_h_ux, t);
			t = new ts();
			c.map.put(tableName.t_huser, t);
			t = new ts();
			c.map.put(tableName.t_loadinfo, t);
			t = new ts();
			c.map.put(tableName.t_local_avg, t);
			t = new ts();
			c.map.put(tableName.t_ourcontact, t);
			t = new ts();
			c.map.put(tableName.t_tips, t);
			t = new ts();
			c.map.put(tableName.t_users, t);
			t = new ts();
			c.map.put(tableName.t_w_default, t);
			t = new ts();
			c.map.put(tableName.t_w_ux, t);
			t = new ts();
			c.map.put(tableName.t_weibo, t);
			t = new ts();
			c.map.put(tableName.t_wuser, t);
			
			ClientDataRecordBase cdrb = new list_ClientDataRecord();
			
			c.map.put(tableName.t_feeds, cdrb);
			
			return 0;
		}
		public tsType()
		{			
			this.init_type();
			this.init();
		}
		public tsType(JSONObject jsono)
		{			
			this.init_type();
			this.c =(map_ClientDataRecord) ClientDataRecordBase.fromJSON(jsono);
		}
		@Override
		protected JSONObject to_JSON() {
			// TODO Auto-generated method stub
			
			return this.toJSON();
			
			
		}
		@Override
		protected void init_type() {
			// TODO Auto-generated method stub
			record_type = ClientDataRecordBase.ClientDataRecord_TYPE.tsType;
		}
		
	}
	
}